package com.easyCms.base.service;

import com.easyCms.base.common.CodeConst;
import com.easyCms.base.dao.AppCheckCodeDAO;
import com.easyCms.base.entity.AppCheckCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class AppCheckCodeSV {
    @Autowired
    private AppCheckCodeDAO appCheckCodeDAO;

    public AppCheckCode findByValidAppCheckCode(String phoneNumber, String verificationCode, int verificationType,
                                                Date date) {
        return appCheckCodeDAO.findByPhoneNumberAndCheckCodeAndCheckCodeTypeAndStateAndExpireDateAfter(phoneNumber,
                verificationCode, verificationType, CodeConst.State.STATE_VALID, date);
    }

    public AppCheckCode findByPhoneNumberAndCheckCodeAndCheckCodeType(String phoneNumber, String verificationCode,
                                                                      int verificationType) {
        return appCheckCodeDAO.findByPhoneNumberAndCheckCodeAndCheckCodeTypeAndState(phoneNumber, verificationCode,
                verificationType, CodeConst.State.STATE_VALID);
    }

    public AppCheckCode save(AppCheckCode appCheckCode) {
        return appCheckCodeDAO.save(appCheckCode);

    }

}
